package com.atguigu.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;

import java.util.Arrays;

/**
 * @Author:zwy
 * @Despriction:
 * @Date:Create in 11:07 2018/7/10
 * @Modify By:
 */
@Aspect
public class LogAspects {
    //抽取公共切入点表达式
    //1本类引用
    //其他切面引用
    @Pointcut("execution(public int com.atguigu.aop.MathCalculator.*(..))")
    public void pointCut(){

    }
    //@Before在目标方法之前切入；切点表达式(指定在哪个方法切入)
    @Before("pointCut()")
    public void logStart(JoinPoint joinPoint){
        System.out.println("方法名称"+joinPoint.getSignature().getName()+"除法运行了。。。。参数列表{"+ Arrays.asList(joinPoint.getArgs())+"}");
    }
    @After("pointCut()")
    public void logEnd(JoinPoint joinPoint){
        System.out.println("方法名称"+joinPoint.getSignature().getName()+"结束。。。。参数列表{"+ Arrays.asList(joinPoint.getArgs())+"}");

    }
    @AfterReturning(value = "pointCut()",returning = "result")
    public void logReturn(JoinPoint joinPoint,Object result){//必须出现在前面
        System.out.println("法名称"+joinPoint.getSignature().getName()+"除法正常返回。。。。返回值==="+result);
    }
    @AfterThrowing(value = "pointCut()",throwing = "execption")
    public void logException(JoinPoint joinPoint,Exception execption){
        System.out.println("方法名称"+joinPoint.getSignature().getName()+"除法异常。。。。参数列表{"+ Arrays.asList(joinPoint.getArgs())+"}"+"{+execption+}");
    }
}
